home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / maclook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  8.8 KB  |  352 lines

  1. /*
  2. *    maclook.c
  3. *    User interface code for NCSA Telnet for the Macintosh
  4. *     by Gaige B. Paulsen
  5. *****************************************************************
  6. *    NCSA Telnet for the Macintosh                                *
  7. *                                                                *
  8. *    National Center for Supercomputing Applications                *
  9. *    Software Development Group                                    *
  10. *    152 Computing Applications Building                            *
  11. *    605 E. Springfield Ave.                                        *
  12. *    Champaign, IL  61820                                        *
  13. *                                                                *
  14. *    Copyright (c) 1986-1992,                                    *
  15. *    Board of Trustees of the University of Illinois                *
  16. *****************************************************************
  17. *
  18. *   User interface for basic telnet with background file transfer
  19. *   capabilities via FTP calls from host.
  20. *
  21. *    This, the Macintosh version also gives each session its own window,
  22. *    provides advanced keyboard translation, Tek emulation, printing/copying
  23. *    of text and graphics and the pasting of text into the active session.
  24. *
  25. *        Requires:
  26. *    menu.c    - Aux. file for handling menu calls
  27. *    event.c    - Aux. file for handling events
  28. *    switch.c- Aux. file for handling swithcher  (the J word is in Event and here )
  29. *
  30. *
  31. *    Revisions:
  32. *    7/92 Telnet 2.6: added support for the 2 global structs, and put all the 
  33. *                    cursors into one array.  Cleaned up defines            Scott Bulmahn
  34. */
  35.  
  36. #ifdef MPW
  37. #pragma segment 4
  38. #endif
  39.  
  40. #include "TelnetHeader.h"
  41. #include "dialog_resrcdefs.h"
  42.  
  43. #define PREFMASTER                    /* So pref structure gets defined Scott! */
  44.  
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48.  
  49. #include <CType.h>
  50. #include <Fonts.h>
  51. #include <Types.h>
  52. #include <Windows.h>
  53. #include <OSEvents.h>
  54.  
  55. #include "netevent.proto.h"
  56. #include "wind.h"
  57. #include "event.proto.h"
  58. #include "macutil.proto.h"
  59. #include "popup.h"
  60. #include "popup.proto.h"
  61.  
  62. #include "rsinterf.proto.h"
  63. #include "vsdata.h"
  64. #include "vskeys.h"
  65. #include "vsinterf.proto.h"
  66. #include "vgtek.proto.h"
  67. #include "tekrgmac.proto.h"
  68. #include "vr.h"
  69. #include "vrrgmac.proto.h" 
  70. #include "network.proto.h"
  71. #include "mydnr.proto.h"
  72. #include "menuseg.proto.h"
  73. #include "prefs.proto.h"
  74. #include "maclook.proto.h"
  75. #include "DlogUtils.proto.h"
  76. #include "telneterrors.h"
  77.  
  78. extern    Cursor *theCursors[];
  79. extern    WindRec
  80.     *screens;        /* Window Records (VS) for :    Current Sessions */
  81.  
  82. extern    short    scrn;
  83. //extern    char    *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  84.  
  85. void MiscUnload(void) {}
  86.  
  87. short detachGraphics( short dnum)
  88. {
  89.     short i=0;
  90.  
  91.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  92.     if (i>=TelInfo->numwindows) return(-1);
  93.     TelInfo->oldgraph[TelInfo->graphs++]=dnum;
  94.     screens[i].curgraph=-1;
  95.     screens[i].termstate=VTEKTYPE;
  96.     screens[i].enabled=1;
  97.     RGdetach(dnum);
  98.     return(0);
  99. }
  100.  
  101. /* Find screen index by Window */
  102. short    WindowPtr2ScreenIndex(WindowPtr wn)
  103. {
  104.     short    i=0;
  105.  
  106.     while((i<TelInfo->numwindows) && (wn!= (WindowPtr)screens[i].wind)) i++;
  107.     if (i>=TelInfo->numwindows) return(-1);
  108.     return(i);
  109. }
  110.  
  111. WindRecPtr    WindowPtr2WindRecPtr(WindowPtr wn)
  112. {
  113.     short    winNum;
  114.     
  115.     winNum = WindowPtr2ScreenIndex(wn);
  116.     
  117.     if (winNum == -1) {
  118.         return nil;
  119.         }
  120.         
  121.     return &screens[winNum];
  122. }
  123.  
  124. /* Find screen index by VS Number */
  125. short findbyVS( short vs)
  126. {
  127.     short i=0;
  128.  
  129.     while((i<TelInfo->numwindows) && (vs!=screens[i].vs)) i++;
  130.     if (i>=TelInfo->numwindows) return(-1);
  131.     return(i);
  132. }
  133.  
  134. void setgraphcurs( void)                /* Called at start of gin */
  135. {
  136.     TelInfo->ginon=1;
  137.     updateCursor(1);
  138. }
  139.  
  140. void unsetgraphcurs( void)                /* Called at start of gin */
  141. {
  142.     TelInfo->ginon=0;
  143.     updateCursor(1);
  144. }
  145.  
  146. short VGalive( short dnum)
  147. {
  148.     short i;
  149.  
  150.     i=0;
  151.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  152.     if (i<TelInfo->numwindows) {
  153.         return(1);
  154.         }
  155.     else {
  156.         i=0;
  157.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  158.         if (i<TelInfo->graphs)
  159.             return(1);
  160.         }
  161.     return(0);
  162. }
  163.  
  164. void destroyGraphics( short dnum)
  165. {
  166.     short i;
  167.  
  168.     i=0;
  169.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  170.     if (i<TelInfo->numwindows) {
  171.         screens[i].curgraph=-1;
  172.         screens[i].termstate=VTEKTYPE;
  173.         screens[i].enabled=1;
  174.         }
  175.     else {
  176.         i=0;
  177.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  178.         while (i<(MaxGraph-1))
  179.             TelInfo->oldgraph[i]=TelInfo->oldgraph[++i];            /* Bump everyone down one slot */
  180.         TelInfo->graphs--;                                /* One less graph to feed */
  181.         }
  182.     VGclose( dnum);
  183. }
  184.  
  185. short FindByVG(short vg)
  186. {
  187.     short i=0;
  188.  
  189.     while((i<TelInfo->numwindows) && (vg!=screens[i].curgraph)) i++;
  190.     if (i>=TelInfo->numwindows) return(-1);
  191.     return(i);
  192. }
  193.  
  194. void TekEnable( short vg)
  195. {
  196.     short change;
  197.  
  198.     change=FindByVG( vg);
  199.     if (change>=0)
  200.         screens[change].enabled=1;
  201. }
  202.  
  203. void    TekDisable( short vg)
  204. {
  205.     short change;
  206.  
  207.     change=FindByVG( vg);
  208.     if (change>=0)
  209.         screens[change].enabled=0;
  210. }
  211.  
  212. /* showNetNumbers    - Show the current network numbers. */
  213. void showNetNumbers( void)
  214. {
  215.     char        tmpout[30];            /* IP Number */
  216.  
  217.     DialogPtr    dptr;                /* dialog box pointer */
  218.     short        scratchshort;
  219.     int            tmp[4];                /* Integer copy of IP Number */
  220.     unsigned char tmp2[4];
  221.     
  222.     netgetip(tmp2);
  223.     for(scratchshort=0; scratchshort<4; scratchshort++)
  224.             tmp[scratchshort] = (int)tmp2[scratchshort];        /* Get integer numbers */
  225.  
  226.     sprintf(&tmpout[0],"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  227.                                         /* create Human-readable numbers */
  228.  
  229.  
  230.     c2pstr(tmpout);                                    /* BYU LSC */
  231.  
  232.     ParamText(0L, (StringPtr)tmpout,0L,0L);                /* BYU LSC - Put Parms in Dlog */
  233.     
  234.     dptr = GetNewMyDialog(MyIPDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  235.     DrawDialog(dptr);                            /* Display Dialog */
  236.  
  237.     ModalDialog(NULL, &scratchshort);            /* Wait for a click */
  238.  
  239.     DisposDialog(dptr);
  240. }
  241.  
  242. /*******************************************************************/
  243. /*  setupkeys
  244. *   Prompt the user for which keys to use for kill, stop and start.
  245. */
  246.  
  247. void setupkeys( void)
  248. {
  249.     DialogPtr dtemp;
  250.     Rect dBox;
  251.     short dItem,kItem,sItem,eItem;
  252.     Handle kbox,sbox,ebox;
  253.     
  254.     char *tempspot;
  255.     
  256.     tempspot = (char *) NewPtr(256);
  257.     if (tempspot == NULL)
  258.         return; //BUGG signal error here
  259.         
  260.     dtemp=GetNewMyDialog( SetupDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  261.  
  262.     SetCursor(theCursors[normcurs]);
  263.     
  264.     GetDItem( dtemp, killbox, &kItem, &kbox, &dBox);    
  265.     GetDItem( dtemp, stopbox, &eItem, &ebox, &dBox);    
  266.     GetDItem( dtemp, startbox, &sItem, &sbox, &dBox);    
  267.  
  268.     *tempspot = 0;
  269.     if (screens[scrn].TELstop > 0) {
  270.         sprintf(tempspot,"^%c",screens[scrn].TELstop^64);
  271.         c2pstr(tempspot);                                    /* BYU LSC */
  272.         SetIText( ebox , (StringPtr)tempspot);
  273.         SelIText( dtemp, stopbox, 0, 32767);
  274.         }
  275.     if (screens[scrn].TELgo > 0) {
  276.         sprintf(tempspot,"^%c",screens[scrn].TELgo^64);
  277.         c2pstr(tempspot);                                    /* BYU LSC */
  278.         SetIText( sbox , (StringPtr)tempspot);
  279.         SelIText( dtemp, startbox, 0, 32767);
  280.         }
  281.     if (screens[scrn].TELip > 0) {
  282.         sprintf(tempspot,"^%c",screens[scrn].TELip^64);
  283.         c2pstr(tempspot);                                    /* BYU LSC */
  284.         SetIText( kbox , (StringPtr)tempspot);
  285.         SelIText( dtemp, killbox, 0, 32767);
  286.         }
  287.     
  288.         dItem=0;                                /* initially no hits */
  289.         while((dItem>3) || (dItem==0)) {        /* While we are in the loop */
  290.             ModalDialog(DLOGwOK_CancelUPP,&dItem);
  291.  
  292. /*
  293. *  intermediate check.  If they hit a key, put its number in the box.
  294. */
  295.             GetIText( kbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  296.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  297.             if (*tempspot < 32 && *tempspot > 0) {
  298.                 sprintf(tempspot,"^%c",*tempspot^64);
  299.                 c2pstr(tempspot);                        /* BYU LSC */
  300.                 SetIText( kbox , (StringPtr)tempspot);                /* BYU LSC */
  301.                 SelIText( dtemp, killbox, 0, 32767 );
  302.                 }
  303.             GetIText( ebox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  304.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  305.             if (*tempspot < 32 && *tempspot > 0) {
  306.                 sprintf(tempspot,"^%c",*tempspot^64);
  307.                 c2pstr(tempspot);                        /* BYU LSC */
  308.                 SetIText( ebox , (StringPtr)tempspot);                /* BYU LSC */
  309.                 SelIText( dtemp, stopbox, 0, 32767);
  310.                 }
  311.             GetIText( sbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  312.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  313.             if (*tempspot < 32 && *tempspot > 0) {
  314.                 sprintf(tempspot,"^%c",*tempspot^64);
  315.                 c2pstr(tempspot);                        /* BYU LSC */
  316.                 SetIText( sbox , (StringPtr)tempspot);                /* BYU LSC */
  317.                 SelIText( dtemp, startbox, 0, 32767);
  318.                 }
  319.                 
  320.             }
  321.                 
  322.     
  323.         if (dItem==DLOGCancel) {
  324.             DisposDialog( dtemp);
  325.             return;
  326.             }
  327.             
  328.         GetIText( kbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  329.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  330.         if (*tempspot != '^') 
  331.             screens[scrn].TELip = -1;
  332.         else
  333.             screens[scrn].TELip = toupper(*(tempspot+1)) ^ 64;
  334.             
  335.         GetIText( ebox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  336.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  337.         if (*tempspot != '^') 
  338.             screens[scrn].TELstop = -1;
  339.         else
  340.             screens[scrn].TELstop = toupper(*(tempspot+1)) ^ 64;
  341.  
  342.         GetIText( sbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  343.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  344.         if (*tempspot != '^') 
  345.             screens[scrn].TELgo = -1;
  346.         else
  347.             screens[scrn].TELgo = toupper(*(tempspot+1)) ^ 64;
  348.             
  349.     DisposDialog( dtemp);
  350.     updateCursor(1);
  351. }
  352.